welcome to the first module collect data from files as I said, we actually store our data in multiple type of files and in this module we are going to learn several of the common ones including the text file CSV file Excel file XML file and HTM file etc and the general step is we are going to read the data stored in those files and then we are going to save those retrieved file retrieved data into dataframes the dataframe will be the utimate goal for us to retrieve data from multiple different resources and we can choose either output the dataframe into a CSV file so that we can continue to work on it or we can go directly from that dataframe for further analysis in order to do that you have to do several setups the first one is you need to Import pandas as pd we have learned that in pandas module the second one is you are going to upload the associated files in this module and upload them into this place you can either drop those files onto this panel then the files will be automatically uploaded or you need to click here and choose the files from your hard disk and when you have these files uploaded when you have the import done then you will be able to continue okay so let's first look at the CSV which is the one we have already tried and we have already practiced in previous modules CSV is the comma separated value files and the general and default step is to read CSV from a path and in that path is where you save that CSV file in terms of Google Collaboratory since we are using the server we have to go to the left panel and find the dots associated with this CSV file click that dot and then copy the path once you copy the path you can paste it into this place because read the CSV simply needed to know where I can find the CSV file and where is the path once you've done that you can execute this line and we normally will print out the head of the dataframe to get a sense of what the data looks like and it has a Unnamed: 0 and work year experience level so on so forth and we can see that if the columns are too many we may not even be able to see that in one screen and we have to scroll to the right to see that the complete picture and if we want to just look at the structure rather than looking into each of the particular value you can use df.info() once you have the df.info() you can see that it has number of columns printed out and in each of the columns, how many data are Non-Null if they are not missing then we basically have non-null value there and also we can see the data type whether there are integers, or objects or strings, and the floats etc and we can see, this is the structure of this dataframe basically executing head() and executing the info() can give us a good sense of the data as well as it indicates we successfully loaded the data from that file sometimes you may want to have the header=None as a optional argument the reason is sometimes the first row is not the name of the columns the data go directly from row number one as the value and row number 2 as the value if that is the case you may want to have the header = None so that you will create the labels automatically because you want to have the column's name not mess up with the value again you have to know your CSV file you have to know that the first line is a name of the column or not of course we are going to use the head and the info again just to retrieve the structure and see if we load it successfully in this case we can see that using header = None is inappropriate because we actually have the first line as our name of the columns and we can see that in here we even have the columns names not that meaningful as before and every single column becomes object is because basically the first row are now all the strings so that will be something you need to pay attention to when you load a CSV, and actually any other file and sometimes we want to do is a header = None which we are going to read our value directly from the first line and sometimes we can have the skiprows equal to certain number we experienced this one in previous modules that if the first several lines are just explanations or some citations or some notes etc we just want to skip them if we can skip them then we don't have to have those lines read into our structure to mess up with our structure and in this case we just experienced because the header = None misclassified the first row as the value make our every single column as object how about we just skip the first row if we skip the first row even though we are still losing the information of names of the columns but we can see that our value will still be okay will not be messed up and the data type of each of the column is still accurate so this will be something you can choose to do as well so header is None or not based on you have the first line or you have the line as the name of the column or not and skip row you go to 0 that is default or 1 or 2 depends on how many first lines you want to skip and there are some other manipulators such as skip the last several lines and just in case some dataset will have the last several lines as explanation of the attributes etc then you can skip the last several lines as well and that will be for example skipfooter and skip the footer basically will stop right at the here is we're going to just lose the last 300 rows and so when we read the df.info() we actually only end up 307 records rather than 607 records so again the default ones will always be very handy however not always will be successful is because every CSV may have a unique structure may have the head or not may have the first several lines or have the last of several lines as explanations so you have to pay special attention to there okay so let's move on to the text okay to read from a text file and you have to know that this text file actually save the data in a similar way as a CSV not always the case but just in case you have a text file save your data use comma to separate your values etc then you can try still use read_csv() to read the text file so the text file I have already included in our module it can download and then upload it into Google Collaboratory when you execute this line you're supposed to see a similar result as I'm having now it's simply because that text file is directly copied from a CSV file another one is Excel which is also very common in a practice to read from Excel file so the general statement is the same read Excel and the path of that Excel file the Excel file is in our Google Drive folder and you can upload it to here so basically the same thing click on the 3 dots copy the path and the paste it there once we read it in you can see that most of the read certain format function will do the same thing and the first line will be default the name of the columns and we are going to start from the first line and we are going to go to the last line so as you can see here when we read the Excel file in we are achieving a similar result another several useful formats for us to read from one is json the other is XML json and XML format is getting more and more popular in terms of the big data era because it has very limited scheme to write your data in for each of the file basically you have the most freedom of writing them as long as you follow the same structure in that particular file then you should be fine and for the json file we are still going to follow the same routine that is we are going to call the read_json and then have the path of the json file you can go and copy path from this part and once we read it in you can see that the json file is successfully read and the result is similar we have the first line as the name of the columns and in the info we can see that we have achieved the same number of records the other one is XML XML again is one of the popular big data storage for our data right now and if you're interested in each of the particular document how they are looking like maybe you can just click them and double click name and then you can have a look on that particular json file we can see that each of the role is actually a schema and defined by the column name and also the value of that column name okay so for the XML file it will read in by read_xml() and then you can paste the path to that XML and then you can achieve similar results as we can see that we have the info printed out we have 607 rows and the also you can see that the data type is also similar and they may be a little bit different for each of the reading and that will be handled later on when we merge the data sets together as an integrated one okay so next we can read from htm file htm file is very popular when we use that for the web pages etc the htm when we read it in as you can see something you have to make special attention is the first 0 or when we read the data from this htm file we actually will have a list and only the first element on the list is the dataframe you are going to retrieve so this will be the thing a little bit different from our previous reading strategy our previous reading strategy is you read the file you get in the dataframe directly and here when you read the file you can only get a list and then you have to choose the first element on the list which is index 0 and pass it to your dataframe once we finish this part we can see that we achieved a same amount of the record and the 607 ones the documentation is right here you can read from the official documentation from pandas the reason I want to show you this documentation is that our field is changing rapidly so in order to keep up to date you have to rely on that documentation rather than on this particular course because the course may be out of date after a certain time we don't know but I just know that it will be for sure be out of date so have this documentation will always be handy and you can always learn more details for your specific scenario